﻿// RasterPsnrDialog.cpp: 实现文件
//

#include "stdafx.h"
#include "zChecker.h"
#include "RasterPsnrDialog.h"
#include "afxdialogex.h"


// CRasterPsnrDialog 对话框

IMPLEMENT_DYNAMIC(CRasterPsnrDialog, CDialogEx)

CRasterPsnrDialog::CRasterPsnrDialog(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_RASTER_PSNR, pParent)
	, m_strRefPath(_T(""))
	, m_strObjPath(_T(""))
	, m_psnr(0)
	, m_sim(0)
{
	
}

CRasterPsnrDialog::~CRasterPsnrDialog()
{
}

void CRasterPsnrDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT_REF_RASTER_PATH, m_strRefPath);
	DDX_Text(pDX, IDC_EDIT_OBJ_RASTER_PATH, m_strObjPath);
	DDX_Text(pDX, IDC_EDIT_OBJ_RASTER_PATH2, m_psnr);
	DDX_Text(pDX, IDC_EDIT_RASTER_SIM_2, m_sim);
}


BEGIN_MESSAGE_MAP(CRasterPsnrDialog, CDialogEx)
	ON_BN_CLICKED(IDOK, &CRasterPsnrDialog::OnBnClickedOk)
	ON_BN_CLICKED(IDC_BUTTON1, &CRasterPsnrDialog::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &CRasterPsnrDialog::OnBnClickedButton2)
END_MESSAGE_MAP()


// CRasterPsnrDialog 消息处理程序


BOOL CRasterPsnrDialog::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	//m_strRefPath = "F:\\Project\\项目实施\\TJ-数据质量检查-2018\\样例数据\\遥感影像对比数据\\数据\\参考影像\\19990910_1.tif";
	//m_strObjPath = "F:\\Project\\项目实施\\TJ-数据质量检查-2018\\样例数据\\遥感影像对比数据\\数据\\参考影像\\20000320_1.tif";
	
	m_strRefPath = "E:\\Document\\2-项目实施\\TJ-数据质量检查-2018\\样例数据\\遥感影像对比数据\\数据\\参考影像\\19990910_1.tif";
	m_strObjPath = "E:\\Document\\2-项目实施\\TJ-数据质量检查-2018\\样例数据\\遥感影像对比数据\\数据\\参考影像\\20000320_1.tif";


	UpdateData(FALSE);


	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CRasterPsnrDialog::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE); 

	ck::data::Raster* pRaster1 = NULL;
	ck::data::Raster* pRaster2 = NULL;
	ck::data::RasterFactory* pRasterFactory = ck::data::RasterFactory::GetInstance();
	RESULTCODE rc = RC_FAILURE;

	pRaster1 = pRasterFactory->CreateRaster();
	pRaster2 = pRasterFactory->CreateRaster();

	pRaster1->SetPath(m_strRefPath);
	pRaster1->Open();

	pRaster2->SetPath(m_strObjPath);
	pRaster2->Open();

	ck::data::RasterBand* pBand1 = pRaster1->GetBand(0);
	ck::data::RasterBand* pBand2 = pRaster2->GetBand(0);
	
	ck::algorithm::raster::SIMProcessor simp;
	simp.SetBand(pBand1, pBand2);
	rc = simp.Execute();
	if (rc == RC_SUCCESS)
	{
		m_sim = simp.GetValue();
		UpdateData(FALSE);
	}

	ck::algorithm::raster::PSNRProcessor psnrp;
	psnrp.SetBand(pBand1, pBand2);
	rc = psnrp.Execute();
	if (rc == RC_SUCCESS)
	{
		m_psnr = psnrp.GetValue();
		UpdateData(FALSE);
	}



	pRaster1->Release();
	pRaster2->Release();

	//CDialogEx::OnOK();
}


void CRasterPsnrDialog::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码
	const char*  szFilter = "Tif文件 (*.tif)|*.tif";
	CString filePath("");
	CFileDialog dlg(TRUE, "TIF", NULL, OFN_HIDEREADONLY, szFilter);

	if (dlg.DoModal() == IDOK)
	{
		m_strRefPath = dlg.GetPathName();
		UpdateData(FALSE);
	}
}


void CRasterPsnrDialog::OnBnClickedButton2()
{
	// TODO: 在此添加控件通知处理程序代码
	const char*  szFilter = "Tif文件 (*.tif)|*.tif";
	CString filePath("");
	CFileDialog dlg(TRUE, "TIF", NULL, OFN_HIDEREADONLY, szFilter);

	if (dlg.DoModal() == IDOK)
	{
		m_strObjPath = dlg.GetPathName();
		UpdateData(FALSE);
	}
}
